import 'dart:math';

class Bicycle {
  int cadence;
  int _speed = 0;
  int gear;

  Bicycle(this.cadence, this.gear);

  @override
  String toString() => 'Bicycle: $_speed mph';

  int get speed => _speed;

  void applyBrake(int decrement) {
    _speed -= decrement;
  }

  void speedUp(int increment) {
    _speed += increment;
  }
}

// void main() {
//   var bike = new Bicycle(2, 1);
//   print(bike);

//   print(Rectangle(origin: const Point(10, 20), width: 100, height: 200));
//   print(Rectangle(origin: const Point(10, 10)));
//   print(Rectangle(width: 200));
//   print(Rectangle());
// }

class Point {
  final num x, y;

  const Point(this.x, this.y);
}

class Rectangle {
  final Point origin;
  final num width, height;

  Rectangle({this.origin = const Point(0, 0), this.width = 0, this.height = 0});
}

abstract class Shape {
  factory Shape(String type) {
    if (type == 'circle') return Circle(2);
    if (type == 'square') return Square(2);
    throw 'Can\'t create $type.';
  }

  num get area;
}

class Circle implements Shape {
  final num radius;

  Circle(this.radius);

  @override
  num get area => pi * pow(radius, 2);
}

class Square implements Shape {
  final num side;

  Square(this.side);

  @override
  num get area => pow(side, 2);
}

main() {
//   final circle = Circle(2);
//   final square = Square(2);
//   print(circle.area);
//   print(square.area);

//	final circle = shapeFactory('circle');
//	final square = shapeFactory('square');
//	print(circle.area);
//	print(square.area);

  final circle = Shape("circle");
  final square = Shape('square');
  print(circle.area);
  print(square.area);
}

Shape shapeFactory(String type) {
  if (type == 'circle') return Circle(2);
  if (type == 'square') return Square(2);
  throw 'Can\'t create $type.';
}
